package com.project.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.entity.po.Member;

import java.util.List;

/**
 * @ProjectName:
 * @Package:
 * @ClassName:
 * @Author: ZhaoLongShi
 * @CreateDate:
 */
public interface MemberMapper extends BaseMapper<Member> {
    /**
     * 根据用户ID获取会员信息
     *
     * @param userId
     * @return
     */
    default Member selectMemberByUserId(Long userId) {
        QueryWrapper<Member> qw = new QueryWrapper<>();
        qw.lambda().eq(Member::getUserId, userId);
        return this.selectOne(qw);
    }

    /**
     * 获取所有会员
     *
     * @param current
     * @return
     */
    default Page<Member> selectAllMember(int current) {
        QueryWrapper<Member> qw = new QueryWrapper<>();
        qw.lambda().eq(Member::getIsDel, 1);
        Page<Member> page = new Page<>(current, 3);
        return this.selectPage(page, qw);
    }

    /**
     * 根据类别查询会员
     *
     * @param cardType
     * @return
     */
    default List<Member> selectByType(int cardType) {
        QueryWrapper<Member> qw = new QueryWrapper<>();
        qw.lambda().eq(Member::getCardType, cardType);
        return this.selectList(qw);
    }


    /**
     * 批量删除会员
     *
     * @param idList
     * @return
     */
    int deleteMemberByIds(List<Long> idList);
}